#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-11-12 
# software: PyCharm
import multiprocessing

def send_message(queue):
    while True:
        message = input("请输入聊天消息（输入'exit'退出）: ")
        if message == "exit":
            break
        queue.put(message)


def receive_message(queue):
    while True:
        if not queue.empty():
            message = queue.get()
            print(f"收到消息: {message}")
        else:
            continue


if __name__ == "__main__":
    message_queue = multiprocessing.Queue()
    send_process = multiprocessing.Process(target=send_message, args=(message_queue,))
    receive_process = multiprocessing.Process(target=receive_message, args=(message_queue,))

    send_process.start()
    receive_process.start()

    send_process.join()
    receive_process.terminate()